package com.bussiness.util;

import com.bussiness.system.model.MyAuthEntity;
import com.bussiness.system.model.MyRoleAuthEntity;
import com.common.vo.TreeVo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @description: 业务公共方法
 * @author: zyj
 * @create: 2020-01-11 11:56
 **/
public class CommonUtils {

    /**
     * 对象转换
     * @param resourceList
     * @return
     */
    public static List<TreeVo> coverTree(List<MyAuthEntity> resourceList, List<MyRoleAuthEntity> roleAuthEntities){
        List<TreeVo> listTree = new ArrayList<TreeVo>();
        if(resourceList!=null&&resourceList.size()>0){
            Iterator<MyAuthEntity> iterator = resourceList.iterator();
            while (iterator.hasNext()){
                MyAuthEntity next = iterator.next();
                long id = next.getId();
                TreeVo treeVo = new TreeVo();
                treeVo.setId(String.valueOf(id));
                treeVo.setName(next.getName());
                treeVo.setParentId(String.valueOf(next.getPid()));
                //设置是否勾选
                for(int i=0;i<roleAuthEntities.size();i++){
                    MyRoleAuthEntity myRoleAuthEntity = roleAuthEntities.get(i);
                    if(id==myRoleAuthEntity.getAuthId()){
                        treeVo.setChecked(true);
                    }
                }
                listTree.add(treeVo);
            }
        }

        return  listTree;
    }
}
